package database

import (
	"go_study/models"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"

	log "github.com/sirupsen/logrus"
)

var DB *gorm.DB

func InitDB() {
	dsn := "root:wl123456@tcp(127.0.0.1:3306)/wl_test?charset=utf8mb4&parseTime=True&loc=Local"
	var err error
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if (err != nil) {
		log.Fatal("数据库连接失败:", err)
	}
	// 自动创建表
	DB.AutoMigrate(&models.User{})
	log.Infof("✅ 数据库连接成功")
}